<template>
  <div id="">
    <div class="qr-main">
      <div class="qr-heard">
        <el-carousel height="220px">
          <el-carousel-item v-for="image in images" v-bind:key="image.url">
            <viewer :images="images">
              <img :src="image.url" class="img">
            </viewer>
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="qr-middle">
        <div class="connent0">
          <div class="connent-bg1">
            <span class="connent-name1">基本信息</span>
          </div>
          <div class="conent1">
            <div class="connent-bg2">
              <div class="connent-table">
                <div class="table-from">
                  <div class="qr-tr">
                    <div class="qr-td1">【植株编号】</div>
                    <div class="qr-td2">{{dataInfo.number}}</div>
                  </div>
                  <div class="div-line"></div>
                  <div class="qr-tr">
                    <div class="qr-td1">【种质类型】</div>
                    <div class="qr-td2">{{dataInfo.type}}</div>
                  </div>
                  <div class="div-line"></div>
                  <div class="qr-tr">
                    <div class="qr-td1">【经度】</div>
                    <div class="qr-td2">{{dataInfo.lon}}</div>
                  </div>
                  <div class="div-line"></div>
                  <div class="qr-tr">
                    <div class="qr-td1">【纬度】</div>
                    <div class="qr-td2">{{dataInfo.lat}}</div>
                  </div>
                  <div class="div-line"></div>
                  <div class="qr-tr">
                    <div class="qr-td1">【海拔】</div>
                    <div class="qr-td2">{{dataInfo.alt}}</div>
                  </div>
                </div>
              </div>
              <phone-corner></phone-corner>
            </div>
          </div>
        </div>
        <div class="connent0" v-for="(data, index) in templateData" :key="index">
          <div class="connent-bg1">
            <span class="connent-name1">{{data.name}}</span>
          </div>
          <div class="conent1">
            <div class="connent-bg2">
              <div class="connent-table">
                <div class="table-from" v-for="(item, i) in data.items" :key="i">
                  <div class="qr-tr">
                    <div class="qr-td1">【{{item.name}}】</div>
                    <div class="qr-td2" v-if="item.type !== 'upload'">{{dataJson[item.name]}}</div>
                    <div class="qr-td2" v-else>
                      <a :href="fileServerUrl + dataJson[item.name]" v-if="dataJson[item.name].length > 0">
                        {{dataJson[item.name].substring(dataJson[item.name].lastIndexOf('/') + 1, dataJson[item.name].length)}}
                      </a>
                    </div>
                  </div>
                  <div class="div-line"></div>
                </div>
              </div>
              <phone-corner></phone-corner>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import resourceApi from '../../../api/resourceApi'
import templateApi from '../../../api/templateApi'
import phoneCorner from '../../../components/phoneCorner'
export default {
  name: 'detailsQrCode',
  components: {
    phoneCorner
  },
  data () {
    return {
      fileServerUrl: process.env.FILE_SERVER,
      // 图片父容器高度
      bannerHeight: 1000,
      // 浏览器宽度
      screenWidth: 0,
      qrcodeInfo: [],
      images: [
        {url: require('../../../assets/img/1.jpg')},
        {url: require('../../../assets/img/2.jpg')},
        {url: require('../../../assets/img/3.jpg')}
      ],
      dataJson: {},
      dataInfo: {},
      templateData: []
    }
  },
  created () {
    let resourceId = this.$route.query.resourceId
    if (resourceId !== undefined) {
      resourceApi.getResourceInfo(resourceId).then((res) => {
        let result = res.data.result
        if (res.data.messageCode === '200' && result) {
          this.dataInfo = result
          this.dataJson = result.dataJson ? JSON.parse(result.dataJson) : {}
          this.$nextTick(() => {
            this.getTemplate(result.templateId)
          })
        }
      })
    } else {
      this.$message.error('请求失败，请先传入参数')
    }
  },
  methods: {
    getTemplate (id) {
      this.templateData = []
      templateApi.findColumn(id).then((res) => {
        let result = res.data.result
        if (res.data.messageCode === '200' && result) {
          this.templateData = result
        }
      })
    }
  }
}
</script>

<style scoped>
  .div-line{
    width: 100%;
    border:0.5px dashed #FFF;
    display: flex;
    justify-content: center;
    margin: 0.35rem 0 0.5rem 0;
  }
  .qr-main {
    background-color: #06306A;
    height: 100%;
  }
  .img{
    width: 100%;
    height: 100%;
  }
.img-qr{
  width: 100%;
  height: 180px;
  margin-bottom: 1.2rem;
}
  .qr-heard {
    width: 100%;
    height: 220px;
  }

  .qr-middle {
    width: 100%;
    height: 100%;
    margin-top: 3rem;
  }
  .connent-bg1 {
    z-index: 999;
    width: 78%;
    height:60px;;
    margin: 0.2rem auto 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0) url(../../../assets/img/qrCode/headT.png) no-repeat scroll 50% 50% / cover;
  }

  .connent-name1 {
    text-align: center;
    font-size: 3.8rem;
    margin-top: -0.3rem;
    color: #fff;
    font-weight: bold;
  }

  .connent{
    margin-top: 2rem;
  }
  .conent1 {
    z-index: 999;
    width: 97%;
    height: 100%;
    margin: 1.2rem auto 0;
    display: flex;
    justify-content: center;
  }

  .connent-bg2 {
    position: relative;
    width: 100%;
    height: 100%;
    display:inline-block;
    margin:10px;
    background: #0062B3;
    background: linear-gradient(135deg, transparent 7vw, #0062B3 0) top left,
    linear-gradient(-135deg, transparent 0px, #0062B3 0) top right,
    linear-gradient(-45deg, transparent 7vw , #0062B3 0) bottom right,
    linear-gradient(45deg, transparent 0px, #0062B3 0) bottom left;
    background-size: 51% 51%;
    background-repeat: no-repeat;
  }
  .conent7 {
    z-index: 999;
    width: 88%;
    height: 100%;
    margin: 0.4rem auto 0;
    display: flex;
    justify-content: center;
    flex-direction: column;
  }

  .connent-text {
    font-size:2rem;
    display: flex;
    flex-direction: row;
    color: #fff;
    margin-left:9%;
  }

  .connent-table {
    margin: 1.5rem 0 1.5rem 2.2rem
  }
  .table-from {
    width: 90%;
    color: #fff;
    display: flex;
    flex-direction: column;
  }

  table.table-from td {
    height: 1.3rem;
    border-left: 0;
    border-right: 0;
    padding-top: 0.6rem;
  }

  .qr-tr {
    width: 100%;
    display: flex;
    flex-direction: row;
  }

  .qr-tr2 {
    border: 0;
  }

  .qr-td1 {
    width: 48%;
    padding-left: 1rem;
    font-size: 2.2rem;
  }

  .qr-td2 {
    width: 52%;
    text-align: center;
    font-size: 2.2rem;
  }
</style>
<style lang="less">
  .el-carousel__item:nth-child(2n) {
    background-color: transparent;
  }

  .el-carousel__item:nth-child(2n+1) {
    background-color: transparent;
  }
</style>
